<?php

namespace App\Kuafu\Log\Service;


use App\Kuafu\Common\Service\CommonService;
use App\Kuafu\Log\Model\UserLoginLogModel;
use Kuafu\IpWhite\Service\IpWhiteService;

class UserLoginLogService
{
    /**
     * 管理员登录日志
     * @param $userId
     * @param $type
     * @param $longitude
     * @param $latitude
     * @param $serialNumber
     * @param $mobile
     */
    public static function addUserLoginLog($userId, $type, $longitude, $latitude, $serialNumber, $mobile, $username, $ip)
    {
        $data = [
            'userId'       => $userId,
            'type'         => $type,
            'mobile'       => $mobile,
            'userName'     => $username,
            'ip'           => (int)ip2long($ip),
            'longitude'    => $longitude,
            'latitude'     => $latitude,
            'serialNumber' => $serialNumber,
            'createdAt'    => time(),
            'updatedAt'    => time()
        ];
        UserLoginLogModel::query()->create($data);

        (new IpWhiteService($userId, $type, null))->login($ip);
    }
}
